package com.atguigu.lease.web.admin.service.impl;


import com.atguigu.lease.model.entity.SystemPost;
import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.admin.mapper.SystemUserMapper;
import com.atguigu.lease.web.admin.service.SystemPostService;
import com.atguigu.lease.web.admin.service.SystemUserService;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 48138
* @description 针对表【system_user(员工信息表)】的数据库操作Service实现
* @createDate 2025-07-05 14:18:49
*/
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
    implements SystemUserService {

    @Autowired
    private SystemUserMapper systemUserMapper;

    @Autowired
    private SystemPostService systemPostService;

    @Override
    public IPage<SystemUserItemVo> pageSystemUserByQuery(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
        return systemUserMapper.pageSystemUserByQuery(page,queryVo);
    }

    @Override
    public SystemUserItemVo getSystemUserById(Long id) {
        //根据用户ID查询用户信息
        SystemUser systemUser = getById(id);
        //将密码设置为null，同时印射不加密码
        systemUser.setPassword(null);
        //根据用户id查询岗位信息
        SystemPost systemPost = systemPostService.getById(systemUser.getPostId());
        //创建新对象
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
        //属性拷贝
        BeanUtils.copyProperties(systemUser,systemUserItemVo);

        systemUserItemVo.setPostName(systemPost.getName());
        return systemUserItemVo;
    }
}




